package math

import (
	"go_gvm_mini/instructions/base"
	"go_gvm_mini/rtda"
	"reflect"
	"strings"
)

type XOR[T interface{}] struct {
	base.NoOperandsInstruction
}

func (self *XOR[T]) Execute(jFrame *rtda.JFrame) {
	stack := jFrame.OperandStack()
	e := reflect.TypeOf(self).Elem().String()
	etype := strings.ReplaceAll(strings.Split(e, "[")[1], "]", "")
	switch etype {
	case "int64":
		v2 := stack.PopInt()
		v1 := stack.PopInt()
		stack.PushInt(v1 ^ v2)
		break
	case "int32":
		v2 := stack.PopInt()
		v1 := stack.PopInt()
		stack.PushInt(v1 ^ v2)
		break
	}

}

type IXOR struct {
	XOR[int32]
}
type LXOR struct {
	XOR[int64]
}
